package com.cinema.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cinema.Bean.Movie;
import com.cinema.dao.IMovieDao;
import com.cinema.dao.imp.MovieDaoMysql;

public class indexServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	// 电影状态  1 正在热映   2 即将上映   3 下映
	private final static int HOT=1;
	private final static int WILL=2;
	private final static int FINISHED=3;
	
	IMovieDao iMovieDao = new MovieDaoMysql();

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		// 正在热映
		List<Movie> hotMovieList=iMovieDao.selectByWhere("movieStat = "+HOT);
		request.setAttribute("hotMovies", hotMovieList);
		
		// 即将上映
		List<Movie> willMovieList=iMovieDao.selectByWhere("movieStat = "+WILL);
		request.setAttribute("willMovies", willMovieList);
		
		/*将电影信息传到主界面*/
		RequestDispatcher rd=request.getRequestDispatcher("/index.jsp");
		rd.forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
